package com.dongdongshop.controller;

import com.dongdongshop.domain.AjaxResult;
import com.dongdongshop.domain.PageResult;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.service.GoodsService;
import com.dongdongshop.service.ItemcatService;
import em.ResuleEnum;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("goods")
public class GoodsController {

    @DubboReference(timeout = 90000)
    private GoodsService goodsService;
    @DubboReference
    private ItemcatService itemcatService;

    @RequestMapping("goodsShow")
    public String goodsShow(){
        return "admin/goods";
    }

    @RequestMapping("goodsList")
    @ResponseBody
    public AjaxResult goodsList(TbGoods tbGoods, @RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "3")Integer pageSize){
        PageResult<TbGoods> list = goodsService.goodsList(tbGoods,pageNum,pageSize);
        List<TbItemCat> itemCatList = itemcatService.selectInfo();
        return AjaxResult.R(ResuleEnum.SUCCESS).setData(list).setRows(itemCatList);
    }

    @RequestMapping("isShenhe")
    @ResponseBody
    public AjaxResult isShenhe(@RequestParam("ids[]")Long[] ids ,TbGoods tbGoods){
            goodsService.isShenhe(ids,tbGoods);
            return AjaxResult.R(ResuleEnum.SUCCESS);
    }

    @RequestMapping("deleteById")
    @ResponseBody
    public AjaxResult deleteById(@RequestParam("ids[]")Long[] ids){
        goodsService.deleteById(ids);
        return AjaxResult.ok();
    }
}
